// place all #?.#?.MyMatch files in your AmIRC directory.
\\
// Usage is: /Rx MyMatch [-Q] [-DEBUG] [-D Dev:dir/path]
\\
// -Q Echos to screen instead of to channel
\\ -DEBUG Enables file searching displays
// -D Dev:Dir Points to location of #?.#?.MyMatch files
\\ -W Country Returns country mask .?? if found.
// -C Mask Returns country name for mask.
\\
*/
;arg opts;opt="";debug=0;dname="";cntry="";flist="";ECmd="say";do while opts ~="";parse value opts with ou opts;select;when ou="?" then;do;"echo P="d2c(27)"««MyMatch»" 'MyMatch Version 2.4 (June 7, 1999) Usage is: /Rx MyMatch [-Q] [-D Dev:dir/] [-W Country] [-C Mask] [-DEBUG]';exit;end;when ou="-DEBUG" then debug=1;when ou="-Q" then;do;opt="-Q";ECmd="echo P="d2c(27)"««MyMatch»";end;when ou="-D" then parse value opts with dname opts;when ou="-C" then;do;parse value opts with mask opts;call SetData();call FindMask();exit;end;when ou="-W" then;do;parse value opts with cntry opts;call SetData();call FindCountry();exit;end;otherwise continue;end;end;if ~show('L',"rexxsupport.library") then;do;if ~addlib("rexxsupport.library",0,-30,0) then;do;"echo P="d2c(27)"««MyMatch»" 'Error ocurred opening rexxsupport.library. EOJ.';exit;end;end;if dname="" then;do;if showlist('a','MCF') then;do;dname="MCF:";flist=upper(showdir(dname,"file"))||" ";if 0=pos(".MYMATCH ",flist) then dname="";end;end;if flist="" then flist=upper(showdir(dname,"file"))||" ";if 0=pos(".MYMATCH ",flist) then;do;"echo P="d2c(27)"««MyMatch»" '.MyMatch data files not found. EOJ.';exit;end;a0=0;do b0=1 by 1 while flist ~="";parse value flist with fn flist;p1=pos(".MYMATCH",fn);if p1 ~=0 then;do;a0=a0+1;fn.a0=fn;p2=pos('.',fn.a0);if p2 ~<p1 then iterate b0;fm.a0=substr(fn.a0,p2+1,p1-p2-1);if (debug) then "echo P="d2c(27)"««MyMatch»" "Processing" fn;if ReadData() then call ParseData();end;end b0;options failat 20;call SetData();options results;getchannel;chan=result;getusers;users=compress(result,'@+');hosts="";ucnt=0;do ac=1 by 1 while users ~="";parse value users with user users;drop result;userhost user;host=result;ucnt=ucnt+1;if host="RESULT" then host="?@?.UNK";xl=lastpos('.',host);xx=upper(substr(host,xl+1));if datatype(xx)="NUM" then call FindIt();if datatype(xx)="NUM" then call solvit();if datatype(xx) ~="CHAR" then xx="UNK";if 0=pos(' '||xx||' ',tags) then call FindIt();if datatype(value(xx))="CHAR" then;interpret xx "= 1";else interpret xx "=" xx "+ 1";if 0=pos(xx,hosts) then hosts=hosts xx;if xx="NET"|xx="COM"|xx="UNK" then;"echo P="d2c(27)"««Error»" user 'has domain name of' host;end ac;if hosts="" then exit;ECmd chan 'has' ucnt 'users';do while hosts ~="";parse value hosts with host hosts;if 0=pos(' '||host||' ',tags) then;ECmd right(value(host),2) "from" host;else;do;do ad=1 by 1 while host ~=tags.ad;end;ECmd right(value(host),2) "from" names.ad;end;end;exit;SetData:;tags=" UNK USA AF AL DZ AS AD AO AI AQ AG AR AM AW AU AT AZ BS BH BD BB BY BE ";tags=tags||" BZ BJ BM BT BO BA BW BV BR IO BN BG BF BI BY KH CM CA CV KY CF ";tags=tags||" TD CL CN CX CC CO KM CG CK CR CI HR HR CU CY CS DK DJ DM DO TP ";tags=tags||" EC EG SV GQ EE ET FK FK FO FJ FI FR GF PF TF GA GM GE DE DE GH ";tags=tags||" GI GR GL GD GP GU GT GN GW GY HT HM HN HK HU IS IN ID IR IQ IE ";tags=tags||" IL IT JM JP JO KZ KE KI KP KR KW KG LA LV LB LS LR LY LI LT LU ";tags=tags||" MO MK MG MW MY MV ML MT MH MQ MR MU MX FM MD MC MN MS MA MZ MM ";tags=tags||" NA NR NP NL AN NT NC NZ NI NE NG NU NF MP NO OM PK PW PA PG PY ";tags=tags||" PE PH PN PL PT PR QA RE RO RU RW KN LC VC WS SM ST SA SN SC SL ";tags=tags||" SG SI SB SO ZA ES LK SH PM SD SR SJ SZ SE CH CH SY TW TJ TZ TH ";tags=tags||" TG TK TO TT TN TR TM TC TV UG UA AE UK GB US UM UY SU UZ VU VA ";tags=tags||" VE VN VI VG WF EH YE YU ZR ZM ZW MIL ORG GOV KP KR LA SU SK CZ ";names="Unknown-Domains United-States-of-America Afghanistan Albania Algeria American-Samoa Andorra";names=names "Angola Anguilla Antarctica";names=names "Antigua-And-Barbuda Argentina Armenia Aruba Australia Austria Azerbaijan Bahamas";names=names "Bahrain Bangladesh Barbados Belarus Belgium Belize Benin Bermuda Bhutan Bolivia";names=names "Bosnia Botswana Bouvet-Island Brazil British-Indian-Ocean-Territory Brunei-Darussalam";names=names "Bulgaria Burkina-Faso Burundi Byelorussian-Ssr Cambodia Cameroon Canada Cap-Verde";names=names "Cayman-Islands Central-African-Republic Chad Chile China Christmas-Island";names=names "Cocos-(keeling)-Islands Colombia Comoros Congo Cook-Islands Costa-Rica Cote-D'ivoire";names=names "Croatia Hrvatska Cuba Cyprus Czechoslovakia Denmark Djibouti Dominica Dominican-Republic East-Timor";names=names "Ecuador Egypt El-Salvador Equatorial-Guinea Estonia Ethiopia Falkland-Islands Malvinas";names=names "Faroe-Islands Fiji Finland France French-Guiana French-Polynesia French-Southern-Territories";names=names "Gabon Gambia Georgia Germany Deutschland Ghana Gibraltar Greece Greenland Grenada Guadeloupe";names=names "Guam Guatemala Guinea Guinea-Bissau Gyana Haiti Heard-And-Mc-Donald-Islands Honduras Hong-Kong";names=names "Hungary Iceland India Indonesia Iran Iraq Ireland Israel Italy Jamaica Japan Jordan Kazakhstan";names=names "Kenya Kiribati North-Korea South-Korea Kuwait Kyrgyzstan Laos Latvia Lebanon Lesotho Liberia";names=names "Libyan-Arab-Jamahiriya Liechtenstein Lithuania Luxembourg Macau Macedonia Madagascar Malawi";names=names "Malaysia Maldives Mali Malta Marshall-Islands Martinique Mauritania Mauritius Mexico Micronesia";names=names "Moldova Monaco Mongolia Montserrat Morocco Mozambique Myanmar Namibia Nauru Nepal Netherlands";names=names "Netherlands-Antilles Neutral-Zone New-Caledonia New-Zealand Nicaragua Niger Nigeria Niue";names=names "Norfolk-Island Northern-Mariana-Islands Norway Oman Pakistan Palau Panama Papua-New-Guinea Paraguay";names=names "Peru Philippines Pitcairn Poland Portugal Puerto-Rico Qatar Reunion Romania Russian-Federation";names=names "Rwanda Saint-Kitts-And-Nevis Saint-Lucia Saint-Vincent-And-The-Grenadines Samoa San-Marino";names=names "Sao-Tome-And-Principe Saudi-Arabia Senegal Seychelles Sierra-Leone Singapore Slovenia";names=names "Solomon-Islands Somalia South-Africa Spain Sri-Lanka St.-Helena St.-Pierre-And-Miquelon Sudan";names=names "Suriname Svalbard-And-Jan-Mayen-Islands Swaziland Sweden Switzerland Cantons-Of-Helvetia";names=names "Syrian-Arab-Republic Taiwan Tajikistan Tanzania Thailand Togo Tokelau Tonga Trinidad-And-Tobago";names=names "Tunisia Turkey Turkmenistan Turks-And-Caicos-Islands Tuvalu Uganda Ukrainian-SSR";names=names "United-Arab-Emirates United-Kingdom Great-Britain United-States-Of-America";names=names "United-States-Minor-Outlying-Islands Uruguay Soviet-Union Uzbekistan Vanuatu Vatican-City-State";names=names "Venezuela Viet-Nam Virgin-Islands-(US) Virgin-Islands-(UK) Wallis-And-Futuna-Islands Western-Sahara";names=names "Yemen Yugoslavia Zaire Zambia Zimbabwe Military-(US) Non-Profit-Organization-(US) Government-(US)";names=names "Korea/Democratic-People's-Republic-Of Korea/Republic-Of Lao-Peoples'-Democratic-Republic Russia";names=names "Slovakia Czech";tgs=tags;nmes=names;do ab=1 by 1 until nmes="";parse value tgs with tags.ab tgs;parse value nmes with names.ab nmes;names.ab=translate(names.ab,' ','-');end ab;return;FindCountry:;if 0=pos(cntry,upper(names)) then;do;"echo P="d2c(27)"««MyMatch»" cntry "not found in country list.";return;end;do fcnt=1 by 1 while fcnt<ab;if 0 ~=pos(cntry,upper(names.fcnt)) then;do;"echo P="d2c(27)"««MyMatch»" d2c(2)names.fcnt d2c(2)"has an ending mask of" d2c(2)tags.fcnt;end;end fcnt;return;FindMask:;if 0=pos(mask,upper(tags)) then;do;"echo P="d2c(27)"««MyMatch»" mask "not found in mask list.";return;end;do tcnt=1 by 1 while mask ~=upper(tags.tcnt);end tcnt;"echo P="d2c(27)"««MyMatch»" d2c(2)tags.tcnt d2c(2)"is the symbol for" d2c(2)names.tcnt;return;ReadData:;fname= dname||fn.a0;if ~open('in',fname) then;do;a0=a0-1;"echo P="d2c(27)"««MyMatch»" "Error ocurred Opening" fname;return;end;fd="";td=readln('in');do while ~eof('in');fd=fd td;td=readln('in');end;call close('in');if strip(fd)="" then return;fd=upper(fd);if (debug) then "echo P="d2c(27)"««MyMatch»" "Done Reading" fn.a0;return 1;ParseData:;do c0=1 by 1 while fd ~="";parse value fd with ft.a0.c0 fd;end c0;mx.a0=c0-1;if (debug) then "echo P="d2c(27)"««MyMatch»" "Parsed" mx.a0 "entries for" fn.a0;return;FindIt:;uhost=upper(host);do d0=1 to a0;do e0=1 to mx.d0;if 0=pos(ft.d0.e0,uhost) then iterate e0;xx=fm.d0;return;end e0;end d0;return;solvit:;xp=pos('@',host);ip=substr(host,xp+1);usr=left(host,xp);cmd='"'"call MatchResolve("ip")"'"';if ip="" then return;address command "Delete >nil: RAM:mr.host";address command "rx >nil:" cmd;if ~open('i',"RAM:mr.host") then return;parse value upper(readln('i')) with j1 j2 domain j;call close('i');address command "Delete >nil: RAM:mr.host";if j1 ~="HOST:"&j1 ~="HOST" then return;if j1="HOST"&j2 ~=ip then return;if j1="HOST:" then domain=j2;host=usr|| domain;xp=lastpos('.',host);xx=substr(host,xp+1);return